﻿using System;
using System.Collections.Generic;
using Tools.Domain.Common.Repositories.Contracts;
using Webshop20.Domain.Orders.Core;
using Webshop20.Domain.Orders.Services.Contracts;
using Webshop20.Domain.Orders.Factories.Contracts;
using System.Linq;
using Webshop20.Domain.Customers.Services.Contracts;

namespace Webshop20.Domain.Orders.Services.Implementation
{
    public class InitializeOrderService : IInitializeOrderService 
    {
        private IOrderFactory orderFactory;
       private IOrderProcessFactory orderProcessFactory;
        private ICustomerInformationService customerInformationService;

        public InitializeOrderService(
                                        IOrderFactory orderFactory, 
                                        
                                        IOrderProcessFactory orderProcessFactory, 
                                        ICustomerInformationService customerInformationService)
        {
            this.orderProcessFactory = orderProcessFactory;
            this.orderFactory = orderFactory;
            this.customerInformationService = customerInformationService;
        }


        //public void StartOrderProcess(string customerEMail, IList<Position> orderPositions)
        //{
        //    var purchaser = purchaserRepository.Find(p => p.EMail == customerEMail).FirstOrDefault();
        //    var order = orderFactory.CreateInstance(purchaser, orderPositions);
        //    var orderProcess = orderProcessFactory.Create(order);

        //    orderProcess.Execute();
    
        //}


        public void StartOrderProcess(int customerId, IList<Position> orderPositions, DateTime orderDate)
        {
            var customer = customerInformationService.GetCustomerById(customerId);
            var order = orderFactory.CreateInstance(customer, orderPositions, null, orderDate);
            var orderProcess = orderProcessFactory.Create(order);

            //orderProcess.Execute();

        }
    }
}
